// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

/// Component health-check status

#pragma once
#include <tuple>

enum HealthStatus {
  HEALTH_UNKNOWN = 0,  // = health-check is not implemented
  HEALTH_OK = 1,
  HEALTH_STARTING = 2,
  HEALTH_RECOVERING = 3,
};

struct Health {
  HealthStatus status;
  int64_t since;
};

inline const char* HealthStatusName(HealthStatus status) {
  constexpr const char* names[] = {"UNKNOWN", "OK", "STARTING", "RECOVERING"};
  return names[status];
}

inline bool operator<(const Health& p, const Health& q) {
  return std::tie(p.status, p.since) < std::tie(q.status, q.since);
}

// Feed
// - Huobi(OK, uptime:23h) -
// - Okex(STARTING, uptime:3h)
//     a1 (OK)
//     a2 (OK)
//     b1 (STARTING, uptime: 1h)
//     b2 (STARTING, uptime: 3h)
// - Okex(RECOVERING, uptime:2h)

// Feed
// - Huobi(OK, uptime:23h) -
// - Okex(STARTING, uptime:3h)
//     a1 (OK)
//     a2 (OK)
//     b1 (STARTING, uptime: 1h)
//     b2 (STARTING, uptime: 3h)
// - Okex(RECOVERING, uptime:2h)

// Feed
// - Huobi(OK, uptime:23h)
// - Okex(STARTING, uptime:3h)
//     "a1 (OK)"
//     "a2 (OK)"
//     "b1 (STARTING, uptime: 1h)"
//     "b2 (STARTING, uptime: 3h)"
// - Okex(RECOVERING, uptime:2h)
